class ChannelUI
{
  
  int id;
  int cheight=16;
  int cwidth=100;
  int stepY = 30;
  
  Channel channel;
  ChannelControlListener listener;
  
  ChannelUI(Channel _this)
  {
      channel = _this;
      println("Start UI Controller: " + channel.id);
      
      int x = 10 + 210*(channel.id+1);
      int y = 10;
     
      listener = new ChannelControlListener();
      listener.channel = channel;
      
      controlP5.addButton("start_"+channel.id,1,x,y,cwidth,cheight).addListener(listener);
      controlP5.controller("start_"+channel.id).setId(0);
      
      y+=stepY;   
      controlP5.addButton("stop_"+channel.id,1,x,y,cwidth,cheight).addListener(listener);
      controlP5.controller("stop_"+channel.id).setId(1);
      
      
      
      y+=stepY;   
      controlP5.addSlider("notes_"+channel.id,2,20,8, x,y, cwidth,cheight).addListener(listener);
      controlP5.controller("notes_"+channel.id).setId(10);
      
      y+=stepY;
      controlP5.addSlider("duration_"+channel.id,100,3000,1000, x,y, cwidth,cheight).addListener(listener);
      controlP5.controller("duration_"+channel.id).setId(11);

      y+=stepY;   
      controlP5.addSlider("prob_silence_"+channel.id,2,20,5, x,y, cwidth,cheight).addListener(listener);
      controlP5.controller("prob_silence_"+channel.id).setId(12);
      
  }
  
  
}


class ChannelControlListener implements ControlListener 
{
  
  Channel channel;
  
  public void controlEvent(ControlEvent theEvent) 
  {
    //println("Channel: " + channel.id);
    //println("got a control event from controller with id "+theEvent.controller().id());
    //println("TheValue: " + theEvent.controller().value() );
    switch(theEvent.controller().id())
    {
        case(0):
          if(theEvent.controller().value() == 1)
          {
             channel.addSequence();
          }
          break;
          
          
        case(10):
          channel.numNotes = int(theEvent.controller().value());
          break;
          
         case(11):
          channel.localDuration = int(theEvent.controller().value());
          break;  

         case(12):
          channel.probSilence = int(theEvent.controller().value());
          break;  
    }
            
  }

}
